<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/5/4
  Time: 16:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String stupic = "http://localhost:8080/stupic/";
    pageContext.setAttribute("stupic", stupic);
%>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学员列表展示</title>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script>
        $(function () {
            $("tr:first").css("background", "gray");
        })

        //删除
        function del(sid) {
            //提示是否确定要删除
            if (confirm("是否确定要删除")) {
                //请求后台servlet完成删除操作
                location.href = "student?method=deleteStudent&sid=" + sid;
            }
        }

        function gotoPage() {
            //获取输入文本框的值
            var currentPage = $('[name="currentPage"]').val();
            //判断输入的页码是否合法
            if (currentPage < 1) {
                alert("页码不能小于1，请输入合法的数字！");
                return;
            }
            if (currentPage >${pu.totalPage}) {
                alert("页码超出范围，请重新输入");
                return;
            }
            //跳转到后台查询
            location.href = "student?method=findAllStudent&currentPage=" + currentPage;
        }
    </script>
</head>
<body>
<table border="1px" width="800px" align="center">


    <caption><h2>学员信息列表展示</h2>
        <br><a href="/addStudent.jsp">添加新学员信息</a>&nbsp;&nbsp;&nbsp;
        <a href="product?method=Productshow">购买商品</a>&nbsp;&nbsp;&nbsp;
        <a href="trolley.jsp">购物车</a>&nbsp;&nbsp;&nbsp;
    </caption>

    <tr>
        <th width="50px">学号</th>
        <th width="60px">姓名</th>
        <th width="50px">性别</th>
        <th width="50px">年龄</th>
        <th width="50px">学历</th>
        <th>头像</th>
        <th>备注</th>
        <th width="150px">操作</th>
    </tr>
    <c:forEach items="${pu.list}" var="stu">
        <tr align="center">
            <td>${stu.sid}</td>
            <td>${stu.sname}</td>
            <td>${stu.sex}</td>
            <td>${stu.age}</td>
            <td>${stu.degree}</td>
            <td align="center">
                <img src="${stupic}${stu.pic}" alt="" width="30px" height="30px">
            </td>
            <td>${stu.mark}</td>
            <td>
                <a href="javascript:void(0)" onclick="del(${stu.sid})">删除</a>&nbsp;&nbsp;&nbsp;
                <a href="student?method=detailedFindStudentBySid&sid=${stu.sid}">修改</a>&nbsp;&nbsp;&nbsp;
                <a href="student?method=findStudentBySid&sid=${stu.sid}">详情</a>&nbsp;&nbsp;&nbsp;
            </td>
        </tr>
    </c:forEach>
    <tr align="center">
        <td colspan="8" height="40px">
            <span>共有${pu.totalPage}页，当前是第${pu.currentPage}页</span> &nbsp;&nbsp;&nbsp;
            <a href="student?method=findAllStudent&currentPage=1">首页</a>&nbsp;&nbsp;&nbsp;
            <a href="student?method=findAllStudent&currentPage=${pu.prePage}">上一页</a>&nbsp;&nbsp;&nbsp;
            <a href="student?method=findAllStudent&currentPage=${pu.nextPage}">下一页</a>&nbsp;&nbsp;&nbsp;
            <a href="student?method=findAllStudent&currentPage=${pu.totalPage}">末页</a>&nbsp;&nbsp;&nbsp;
            跳转到<input type="text" name="currentPage" size="4">页
            <input type="button" value="GO" onclick="gotoPage()">

        </td>
    </tr>
</table>
</body>
</html>